package com.h117121.fashionshop.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.h117121.fashionshop.core.dom.AdsImageForm;

public class AdsValidator implements Validator {

	@SuppressWarnings("rawtypes")
	@Override
	public boolean supports(Class clazz) {
		return AdsImageForm.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		AdsImageForm adsForm = (AdsImageForm) target;
		if (adsForm.getImageLeft().getSize() == 0
				&& adsForm.getImageRight().getSize() == 0) {
			errors.rejectValue("imageLeft", "required.imageLeft");
			errors.rejectValue("imageRight", "required.imageRight");
		}
	}

}
